﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.StartOrder.IView;

namespace MINERP.StartOrder.Forms
{
    public partial class FrmConfig : Form
    {
        public FrmConfig()
        {
            InitializeComponent();
        }

        private void FrmConfig_Load(object sender, EventArgs e)
        {
            txtWuCha.Text = Properties.Settings.Default.PhotoWuCha.ToString("0.00");
            txtOrderLocalPath.Text = Properties.Settings.Default.OrderLocalPath;
            chkOrderByctmFolder.Checked = Properties.Settings.Default.OrderBYCtmFolder;
            chkshopPaperType.Checked = Properties.Settings.Default.UserShopDefaultPaperType;
            chkshopPaperFace.Checked = Properties.Settings.Default.UserShopDefaultPaperFace;

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.PhotoWuCha = Convert.ToDouble( txtWuCha.Text.Trim());
            Properties.Settings.Default.OrderLocalPath =txtOrderLocalPath.Text;
            Properties.Settings.Default.OrderBYCtmFolder = chkOrderByctmFolder.Checked;
            Properties.Settings.Default.UserShopDefaultPaperType = chkshopPaperType.Checked;
            Properties.Settings.Default.UserShopDefaultPaperFace = chkshopPaperFace.Checked;
            Properties.Settings.Default.Save();
            this.Close();
        }

        private void btnBrowser_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == folderBrowserDialog1.ShowDialog())
            {
                txtOrderLocalPath.Text = folderBrowserDialog1.SelectedPath;
            }
        }
        private void SaveRules()
        {
            string strRules = "";
            for (int i = 0; i < listBoxCopyRule.Items.Count; i++)
            {
                var item = listBoxCopyRule.Items[i];
                strRules += (string)item + ",";

            }
            strRules = strRules.Trim(',');
            Properties.Settings.Default.StringCopyRule = strRules;
            Properties.Settings.Default.Save();
            DataTransfer.CopyRule = strRules;

        }

        private void buttonAddRule_Click(object sender, EventArgs e)
        {
            string addStr = textBoxRule.Text.Trim();
            bool isAdd = true;
            if (!string.IsNullOrEmpty(addStr))
            {

                for (int i = 0; i < listBoxCopyRule.Items.Count; i++)
                {
                    var item = listBoxCopyRule.Items[i];
                    if (addStr.Equals((string)item))
                    {
                        isAdd = false;
                        break;
                    }
                }
                if (isAdd)
                {
                    listBoxCopyRule.Items.Add(addStr);
                    SaveRules();
                }
            }
        }

        private void buttonDelRule_Click(object sender, EventArgs e)
        {
            listBoxCopyRule.Items.Remove(listBoxCopyRule.SelectedItem);
            SaveRules();
        }

        private void label9_Click(object sender, EventArgs e)
        {

        }
    }
}
